package com.ysyc.driver_ee.activity;

import android.app.Dialog;
import android.support.v7.widget.RecyclerView;

import com.ysyc.driver_ee.R;
import com.ysyc.driver_ee.adapter.DistributeOrderAdapter;
import com.ysyc.driver_ee.api.HttpResource;
import com.ysyc.driver_ee.api.NetworkCallback;
import com.ysyc.driver_ee.api.RetrofitClient;
import com.ysyc.driver_ee.base.BaseActivity;
import com.ysyc.driver_ee.factory.RecyclerViewFactory;
import com.ysyc.driver_ee.model.DriverInfo;
import com.ysyc.driver_ee.tools.ToastUtils;
import com.ysyc.driver_ee.widget.TitleView;

import java.util.List;

import butterknife.BindView;
import io.reactivex.Observable;

/**
 * <p>描述：(派单页面)</p>
 * 作者： Chan<br>
 * 日期： 2018/11/7 19:52<br>
 * 版本： v1.0<br>
 */
public class DistributeOrderActivity extends BaseActivity {
    @BindView(R.id.title_distribute_order_view)
    TitleView titleDistributeOrderView;
    @BindView(R.id.rl_distribute_order_view)
    RecyclerView rlDistributeOrderView;
    public NetworkCallback<List<DriverInfo>> driverListNetworkCallback;
    private DistributeOrderAdapter adapter;
    public String orderNumber;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_distribute_order;
    }

    @Override
    protected void initView() {
        orderNumber = getIntent().getStringExtra("orderNumber");
        titleDistributeOrderView.setLeftImg(R.drawable.left_return_icon);
        titleDistributeOrderView.setLeftText("派单");
        titleDistributeOrderView.setLeftTextClick(v -> finish());
        RecyclerViewFactory.initVerticalRvDecoration(this, rlDistributeOrderView, 10);
        adapter = new DistributeOrderAdapter(this, R.layout.rv_distribute_order_item);
        rlDistributeOrderView.setAdapter(adapter);
        initNetworkCallback();
    }

    public void initNetworkCallback() {
        driverListNetworkCallback = new NetworkCallback<>(new HttpResource<List<DriverInfo>>() {
            @Override
            public void onSuccess(List<DriverInfo> driverList) {
                adapter.bindingList(driverList);
                dismissDilog();

            }

            @Override
            public void onFailure(String errorDes) {
                dismissDilog();
                ToastUtils.show(errorDes);
            }

            @Override
            public void onLoading(Dialog dialog) {
                showLoadingDialog();
            }
        });
        Observable<List<DriverInfo>> driverListObservable = RetrofitClient.getInstance().getHttpServices().getDriverList(0);
        driverListNetworkCallback.postRequest(driverListObservable, null);
    }


}
